package 力扣._00周赛._428周赛.问题3;

class Solution {
    public int beautifulSplits(int[] nums) {
        // 暴力试水
        int n = nums.length;
        int res = 0;

        for (int i = 1; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int len1 = i, len2 = j - i, len3 = n - j;
                if(len1<=0||len2<=0||len3<=0){
                    continue;
                }
                if(len2>=len1){
                    // 判断子数组1是否是子数组2的前缀
                    if(isPre(nums, 0, len1)){
//                        System.out.println(0+" "+len1);
                        res++;
                        continue;
                    }
                }
                if(len2<=len3) {
                    // 判断子数组2是否是子数组3的前缀
                    if (isPre(nums, i, len2)) {
//                        System.out.println(i+" "+len2);
                        res++;
                    }
                }
            }
        }
        return res;
    }

    private static boolean isPre(int[] nums, int index, int len) {
        boolean flag = true;
        for (int k = index; k < index+len; k++) {
            if(nums[k] != nums[k + len]){
                flag = false;
                break;
            }
        }
        return flag;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
//        int[] nums = {2,3,2,2,1};
//        int[] nums = {1,1,2,1};
        int len = 5000;
        int[] nums = new int[len];
        for (int i = 0; i < len; i++) {
            nums[i] = 1;
        }
        System.out.println(solution.beautifulSplits(nums));
    }
}